library(plyr)
library(dplyr)
library(tidyverse)
library(gsynth)
library(stargazer)
library(xtable)

setwd("~/Dropbox/China Huawei Paper/Production Materials/Replication/")
master.data <- read.csv("dataFile_China_Huawei.csv"); head(master.data)

dat <- master.data
dat$gdppc[dat$gdppc==Inf]=NA
dat = dat[dat$year==2000,]

sub = dat[dat$v2x_polyarchy>0.42,]
sub = sub[sub$cabb!="MNG",]
sub = sub[sub$cabb!="SSD",]
sub = sub[is.na(sub$v2smgovfilprc)==F & is.na(sub$v2x_polyarchy)==F & is.na(sub$pres.election)==F & is.na(sub$coup.attempts)==F & is.na(sub$successful.coups)==F,]
sub = sub[is.na(sub$pcGDPcur)==F & is.na(sub$GDPcur)==F & is.na(sub$electricitypc)==F,]
nrow(dat);nrow(sub)
dem = sub

sub = dat[dat$v2x_polyarchy<=0.42,]
sub = sub[sub$cabb!="MNG",]
sub = sub[sub$cabb!="SSD",]
sub = sub[is.na(sub$v2smgovfilprc)==F& is.na(sub$v2x_polyarchy)==F & is.na(sub$pres.election)==F & is.na(sub$coup.attempts)==F & is.na(sub$successful.coups)==F,]
sub = sub[is.na(sub$pcGDPcur)==F & is.na(sub$GDPcur)==F & is.na(sub$electricitypc)==F,]
nrow(dat);nrow(sub)
aut = sub

dem = data.frame(mean(dem$gdppc,na.rm=T), mean(dem$v2smgovfilprc,na.rm=T), mean(dem$v2smgovshut,na.rm=T), mean(dem$v2smgovsmmon,na.rm=T), mean(dem$v2smarrest,na.rm=T))
aut = data.frame(mean(aut$gdppc,na.rm=T), mean(aut$v2smgovfilprc,na.rm=T), mean(aut$v2smgovshut,na.rm=T), mean(aut$v2smgovsmmon,na.rm=T), mean(aut$v2smarrest,na.rm=T))

names(dem)=c("GDP Per Capita","Internet Filtering","Internet Shutdowns","Social Media Monitoring","Arrests for Political Content")
names(aut)=c("GDP Per Capita","Internet Filtering","Internet Shutdowns","Social Media Monitoring","Arrests for Political Content")

out = rbind(dem,aut)

xtable(out,caption="Digital Surveillance in Democracies and Autocracies in 2000",label="Table: 2000 Values")
        

